package servlet.Course;

import bean.Course;
import bean.Student;
import dao.impl.CourseDaoImpl;
import dao.impl.StudentIDaoImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/course/search")
public class CourseSearch extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");//请求编码
        resp.setContentType("text/html;charset=utf-8");//响应编码
        String cname = req.getParameter("cname");
        CourseDaoImpl dao = new CourseDaoImpl();
        HttpSession session = req.getSession();
        List<Course> courseList = dao.getStudentsByName(cname);
        System.out.println(courseList);
        session.setAttribute("courseList", courseList);
        resp.sendRedirect("/course/showCourse.jsp");
    }
}
